﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.ObjectBuilder;
using Microsoft.Practices.CompositeWeb;
using ModulesToolkit.DataAccess.Membership;
using ModulesToolkit.DataContracts.Membership;
using ModulesToolkit.DataContracts;

namespace ModulesToolkit.Membership.Views
{
    public class RightsPresenter : Presenter<IRightsView>
    {

        // NOTE: Uncomment the following code if you want ObjectBuilder to inject the module controller
        //       The code will not work in the Shell module, as a module controller is not created by default
        //
        // private IMembershipController _controller;
        // public RightsPresenter([CreateNew] IMembershipController controller)
        // {
        // 		_controller = controller;
        // }

         ScreensRipository screensRipository = new ScreensRipository();
         ScreensSearchCriteria SearchScreens = new ScreensSearchCriteria();
         ScreenRightsDtoRipository screenRightsRipository = new ScreenRightsDtoRipository();
         ScreenRightDtoSearchCriteria SearchScreenRights = new ScreenRightDtoSearchCriteria();


        public RightsPresenter(ScreensRipository Screens)
        { 
            
        }
        public override void OnViewLoaded()
        {
            // TODO: Implement code that will be executed every time the view loads
        }

        public override void OnViewInitialized()
        {
            SearchScreenRights.ScreenId = this.View.GetSelectedValue();
            EntitySearchResult<Screens> AllScreens = screensRipository.GetScreens(SearchScreens);
            this.View.FilluxScreensList(AllScreens);

            EntitySearchResult<ScreenRightsDto> AllRights = screenRightsRipository.RetrieveScreenRights(SearchScreenRights);
            this.View.FilluxRightsList(AllRights);

            
            // TODO: Implement code that will be executed the first time the view loads
        }

        public void OnSelectedIndexChanged()
        {
            SearchScreenRights.ScreenId = this.View.GetSelectedValue();
            EntitySearchResult<ScreenRightsDto> AllRights = screenRightsRipository.RetrieveScreenRights(SearchScreenRights);
            this.View.FilluxRightsList(AllRights);
        }

        public void OnLoadRightsList(int PIndex , int PSize, string SField, string SDirection)
        {
            SearchScreenRights.ScreenId = this.View.GetSelectedValue();
            SearchScreenRights.PageNumber = PIndex;
            SearchScreenRights.PageSize = PSize;
            SearchScreenRights.SortField = SField;
            SearchScreenRights.SortDirection = SDirection;
            EntitySearchResult<ScreenRightsDto> AllRights = screenRightsRipository.RetrieveScreenRights(SearchScreenRights);
            this.View.FilluxRightsList(AllRights);
        }


        // TODO: Handle other view events and set state in the view



        

    }
}




